package com.levi.consumer;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author shentong
 * @since 2022/6/9 9:06 PM
 */
@Component
public class TransactionConsumer {
    String consumerGroup = "orderGroup";

    DefaultMQPushConsumer consumer;

    @Autowired
    private ConsumerListener consumerListener;


    @PostConstruct
    public void init() throws MQClientException {
        consumer = new DefaultMQPushConsumer(consumerGroup);
        consumer.setNamesrvAddr("124.220.27.193:9876");
        consumer.subscribe("order","*");
        consumer.registerMessageListener(consumerListener);
        //如果消费失败的最大重试次数
        consumer.setMaxReconsumeTimes(3);
        consumer.start();
    }
}
